package com.Day6;

/**
 * Copyright (C), 2018-2021, 若若叶
 * Author: Hx162
 * Date: 2021/7/13 13:27
 * FileName: MyStack
 * Description: 模拟 栈
 */

/**
 *  模拟一个栈
 *  有入栈，出栈，遍历栈三个功能
 *  栈满，栈空 提示
 *  栈满不得入栈
 *  栈空不得出栈
 */
public class MyStack {
    static Object[] stack = new Object[10];
    static int pointer = 0;

    public static void push(int dser) {
        if (pointer < 10) {
            stack[pointer] = dser;
            if (pointer == 10) {
                System.out.println("栈满...");
            }
            pointer++;
        } else {
            System.out.println("栈已满，无法入栈...");
        }
    }

    public static void pop() {
        if (pointer > 0) {
            pointer--;
            stack[pointer] = null;
            if (pointer == 0) {
                System.out.println("栈空...");
            }
        }else {
            System.out.println("栈已空，无发出栈...");
        }
    }

    public static void print(Object[] o) {
        for (int i = 0; i < o.length; i++) {
            System.out.print(o[i] + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
//        push(12);
//        push(13);
//        push(14);
//        push(15);
//        push(16);
//        push(16);
//        push(16);
//        push(16);
//        push(16);
//        push(17);
//        push(16);
//        print(stack);
//        pop();
//        pop();
//        pop();
//        print(stack);
    }
}
